<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
     
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="发票编号"
          hasFeedback >
          <a-input placeholder="请输入发票编号" v-decorator="['invoiceNumber', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="发票金额"
          hasFeedback >
          <a-input type="number" placeholder="请输入发票金额" v-decorator="['invoiceAmount', {}]" />
        </a-form-item>
<!--  <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="状态"
          hasFeedback >
 <a-select
   v-decorator="['status', {}]"
      style="width: 120px"
      @focus="focus"
      ref="select"
      @change="handleChange"
    >
      <a-select-option value="0">
        未开票
      </a-select-option>
      <a-select-option value="1">
        已开票
      </a-select-option>
 
    </a-select>
        </a-form-item> -->
<a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <!-- <j-image-upload class="avatar-uploader" text="上传" v-model="fileList" style="margin-top: 8px;"></j-image-upload> -->
                  <!-- <el-upload
  style="margin-top: 20px;"
  action="http://clound_clothing.wenkangkeji.com/mlcc/user/interface/uploadImage"
  list-type="picture-card"
  :limit="1"
  :on-exceed="handleExceed"
  :on-preview="handlePictureCardPreview"
  :on-remove="handleRemove"
  :on-success="handleSuccess"
  ref="upload">
  <i class="el-icon-plus"></i>
</el-upload> -->
             上传凭证
            <j-image-upload class="avatar-uploader" text="上传" v-model="fileList" style="margin-top: 8px;"></j-image-upload>
       
                </a-form-item>
 
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
 import JImageUpload from '../../../components/jeecg/JImageUpload'
  export default {
    name: "addInvoice",
     components: {
      JImageUpload
    },
    data () {
      return {
		  status:1,
         fileList: [],
        supplierId:'',
        pingzheng:'',
        userId:'',
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/Finance/addInvoice",
          edit: "/Finance/addInvoice",
        },
      }
    },
    created () {
    },
    methods: {
       //上传图片成功函数
      handleSuccess(response, file, fileList) {
        var result = response;
        this.pingzheng = result.data;
      },
      add () {
        this.edit({});
      },
      edit (record,type) {
        if(type==0){
           this.userId=record;
        }else{
          this.supplierId=record;
        }
      
        console.log("输出看一看吧"+record);
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'name','keyWord','sex','age','email','content'))
		      //时间格式化
          this.form.setFieldsValue({punchTime:this.model.punchTime?moment(this.model.punchTime,'YYYY-MM-DD HH:mm:ss'):null})
          this.form.setFieldsValue({birthday:this.model.birthday?moment(this.model.birthday):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
				if(this.fileList==''){
					    this.$message.success("请选择图片");
							return;
				}
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);


            console.log("看一看传进来的参数"+formData);
            //时间格式化
            formData.punchTime = formData.punchTime?formData.punchTime.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.birthday = formData.birthday?formData.birthday.format():null;
            formData['userId']=this.userId;
            formData['supplierId']=this.supplierId;
             formData['voucher']=this.fileList;
			    formData['status']=this.status;
			 
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('aaa');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>